#ifndef _XDB_CONFIG_H
#define _XDB_CONFIG_H

#include <string.h>
#include <map>
#include <string>
#include <boost/format.hpp>

namespace xdragonball
{
class Config
{
public:
	inline int32_t to_int32() const { 
		return atoi(_str.c_str()); 
	}
	inline int64_t to_int64() const { 
		return atoll(_str.c_str()); 
	}
	inline double to_double() const { 
		return atof(_str.c_str()); 
	}
	inline const std::string & to_string() const { 
		return _str;
	}
	Config & operator [] (const std::string &key);
	const Config & operator [] (const std::string &key) const;
	
	Config & get(const std::string &key, const char * flag=".");
	const Config & get (const std::string &key, const char *flag=".") const;

	template <typename T>
	inline Config & operator = (const T & val) {
		this->_str = (boost::format("%1%")%val).str();
		return *this;
	}

	Config() : _map(NULL) {}
	template <typename T>
	Config(const T &val) : _map(NULL) {
		this->_str = (boost::format("%1%")%val).str();
	}

private:
	std::map<std::string, Config *> *_map;
	std::string _str;
};

int ConfigLoader(Config &cfg, const std::string &file);

};

#endif
